﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web.Mvc;
using CodeCamp.Models.Shared;
using CCM = CodeCamp.Model;

namespace CodeCamp.Models.Email
{
    public class EmailCampaignEditModel
    {
        public EmailCampaignEditModel()
        {
        }

        public EmailCampaignEditModel(CCM.EmailCampaign cm)
        {
            if (cm != null)
            {
                this.Id = cm.Id;
                this.CreatedBy = cm.CreatedBy;
                this.CreatedUTC = cm.CreatedUTC;
                this.Description = cm.Description;
                this.EmailView = cm.EmailView;
                this.EventId = cm.EventId;
                this.RecipientType = cm.RecipientType;
                this.ReplyToAddress = cm.ReplyToAddress;
                this.Salutation = cm.Salutation;
                this.Status = cm.CampaignStatus;
                this.Subject = cm.Subject;
                this.UpdatedBy = cm.UpdatedBy;
                this.UpdatedUTC = cm.UpdatedUTC;
            }
        }

        public int Id { get; set; }
        public int EventId { get; set; }

        [Required]
        public CCM.EmailCampaign.EmailCampaignStatus Status { get; set; }

        [Required]
        public int StatusID
        {
            get { return (int)Status; }
            set { Status = CCM.EmailCampaign.GetCampaignStatus(value); }
        }

        public SelectList StatusSelectList
        {
            get
            {
                var statusItems = from CCM.EmailCampaign.EmailCampaignStatus s in Enum.GetValues(typeof(CCM.EmailCampaign.EmailCampaignStatus))
                                  select new { ID = (int)s, Name = s.ToString() };
                return new SelectList(statusItems, "ID", "Name", CCM.EmailCampaign.EmailCampaignStatus.Undefined.ToString());
            }
        }

        [Required]
        public CCM.EmailCampaign.EmailRecipientType RecipientType { get; set; }

        [Required]
        public int RecipientTypeId
        {
            get { return (int)RecipientType; }
            set { RecipientType = CCM.EmailCampaign.GetRecipientType(value); }
        }

        public SelectList RecipientTypeSelectList
        {
            get
            {
                var recipientTypeItems = from CCM.EmailCampaign.EmailRecipientType rt in Enum.GetValues(typeof(CCM.EmailCampaign.EmailRecipientType))
                                  select new { ID = (int)rt, Name = rt.ToString() };
                return new SelectList(recipientTypeItems, "ID", "Name", CCM.EmailCampaign.EmailRecipientType.Undefined.ToString());
            }
        }

        [Required]
        [MaxLength(256)]
        public string EmailView { get; set; }

        [Required]
        [MaxLength(192)]
        public string Subject { get; set; }

        [MaxLength(192)]
        public string ReplyToAddress { get; set; }

        [Required]
        [MaxLength(512)]
        public string Description { get; set; }

        [Required]
        [MaxLength(256)]
        public string Salutation { get; set; }

        public DateTime CreatedUTC { get; protected set; }

        public string CreatedBy { get; set; }

        public Nullable<DateTime> UpdatedUTC { get; set; }

        public string UpdatedBy { get; set; }
   
    }
}